﻿using CardMaker.Library.Models;

namespace CardMaker.Library.Pages;

public partial class Test {
    private CardTemplate _card = new();
    private CardTemplate _cardTemplate = new();
    private bool _isLoading = true;
    private string frameImg;
    private List<JSideImage> jSideImage=new List<JSideImage>();
    protected override void OnAfterRender(bool firstRender)
    {
        if (!firstRender)
            return;
        Task.Run(async () => {
            //todo 需要做一个初始化页面 目前需要先点击creatcard页面
            await _sideImageStorage.InitializeAsync();
            
            await _cardTemplateStorage.InitializeAsync();

            await _frameImageStorage.InitializeAsync();
            await _cardImageToUrlService.InitModuleAsync();

            _cardTemplate = await _cardTemplateStorage.GetCardTemplateAsync(1);//获取模板id为1的模板


             jSideImage = (List<JSideImage>)await _createCardService.GetJSideImagesUrlAsync(_cardTemplate);//获取副图
             
             frameImg =
                 await _createCardService.GetFrameImageAsync(_cardTemplate);//获取框图url

            _isLoading = false;

            await InvokeAsync(StateHasChanged);
            foreach (var sideImage in jSideImage) {
                foreach (var url in sideImage.SideKeXuanImageUrls) {
                    await _cardImageToUrlService.RevokeUrl(url);
                }
            }
            /*await _cardImageToUrlService.RevokeUrl();//无用，待调整*/
        });
    }
}